package com.wasp.collector;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.wasp.collector.content.Content;
import com.wasp.collector.content.IContentHandler;
import com.wasp.collector.data.HandledDataWrapper;
import com.wasp.collector.data.RequestContext;
import com.wasp.collector.data.RequestWrapper;
import com.wasp.collector.service.HttpClientExecutors;
import com.wasp.collector.service.akka.ActorResult;
import com.wasp.collector.service.akka.cluster.AkkaService;
import com.wasp.collector.service.chain.AbstractHandleChain;
import com.wasp.collector.service.chain.FileHandleChain;
import com.wasp.collector.service.chain.IFileRule;
import com.wasp.collector.utils.IConstant;

public class Samples implements Serializable{
	
	public static void main(String[] args) {
		AkkaService.iniAkka();
		String url1 = "http://guba.eastmoney.com/list,000875,f_1.html";
		String url2 = "http://guba.eastmoney.com/list,000875,f_2.html";
		Map<String,Object> rc = Maps.newHashMap();
		rc.put(IConstant.FILENAME, "00875.txt");
		RequestContext c1 = new RequestContext(url1, rc);
		RequestContext c2 = new RequestContext(url2, rc);
		List<RequestContext> contexts = Lists.newArrayList();
		contexts.add(c1);
		contexts.add(c2);
		
		RequestWrapper wrapper = RequestWrapper.create();
		wrapper.setGet().setRetryHandler(3, 3, null);
		
		AbstractHandleChain handleChain = new FileHandleChain(new IFileRule() {
			
			@Override
			public String pathRule() {
				return "/download";
			}
		});
		IContentHandler handler = new IContentHandler(handleChain) {
			
			@Override
			public void handleError(ActorResult errors) {
				
			}

			@Override
			public HandledDataWrapper generateData(Content c) {
				return null;
			}
			
		};
		HttpClientExecutors es = new HttpClientExecutors();
		es.setRequestContexts(contexts).setContentHandler(handler).setRequest(wrapper).collect();
	}
}